<template>
  <div class="numberCode">
    <el-table
      :data="materielDialogData"
      height="230px"
      :cell-style="{ padding: '2px 0' }"
      @row-click="materielSelectRow"
    >
      <el-table-column :label="$t('market.fmaterial')" prop="fnumber" align="center" min-width="120px" show-overflow-tooltip />
      <el-table-column :label="$t('shop.name1')" prop="fname" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('market.fmodel')" prop="fmodel" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('market.descrip')" prop="fdescripTion" min-width="200px" align="left" header-align="center" show-overflow-tooltip />
      <el-table-column :label="$t('shop.specifica')" prop="fspecificaTion" align="center" show-overflow-tooltip />
    </el-table>
  </div>
</template>

<script>
import { queryMaterialList } from '@/api/marketManage/marketOrder'
import { queryBomSonList } from '@/api/engineering/createBom'
import { Disable, toMxAmina } from '@/components/ToMxamineState'
import { queryTPurPatMatList } from '@/api/marketManage/salesPicing'

export default {
  name: 'NumberCode',
  props: {
    bomCode: {
      type: String,
      default: '0'
    },
    fnumber: {
      type: String,
      default: ''
    },
    fnumbers: {
      type: String,
      default: ''
    },
    materielid: {
      type: [String, Number],
      default: '' || 0
    }
  },
  data() {
    return {
      ftype: 0,
      total: 0,
      fnumber1: '',
      pageNum: 1,
      pageSize: 20,
      materielDialogData: []
    }
  },
  watch: {
    fnumber: {
      handler() {
        if (this.fnumber) {
          this.handleGetMateriel()
        }
      },
      immediate: true
    }
  },
  methods: {
    // 物料弹窗选中
    async materielSelectRow(item) {
      this.prodValue = item
      this.$emit('material', this.prodValue)
    },
    // 打开物料编码
    async handleGetMateriel() {
      const DATA = {
        fid: this.materielid,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        fnumber: this.fnumber,
        materialfnumber: this.fnumber,
        fnumbers: this.fnumbers
        // fid: this.msg1
      }
      // 发起请求
      if (this.bomCode === '0') {
        const { data: RES } = await queryMaterialList(DATA)
        this.materielDialogData = RES.array
        this.total = RES.total
      } else if (this.bomCode === '1') {
        const { data: RES } = await queryTPurPatMatList(DATA)
        this.materielDialogData = RES.list
        this.total = RES.total
      } else {
        const { data: res, total } = await queryBomSonList(DATA)
        this.materielDialogData = res.map(item => {
          return (toMxAmina(item), Disable(item))
        })
        this.total = total
      }
    }
  }
}
</script>
<style lang="scss" scope>
</style>
